Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 1.61 KB

where-bulk-contains.md

File metadata and controls

41 lines (30 loc) · 1.61 KB
title description canonical status lastmod
EF Core Where Bulk Contains
The WhereBulkContains method let you filter a LINQ query by including all items from an existing list.
/bulk-extensions/where-bulk-contains
Published
2023-03-02

EF Core Where Bulk Contains

Entity Framework Extensions provides the WhereBulkContains extension method that allows you to filter a LINQ query by including all items from an existing list.

For example, you have a list of Customer with the CustomerID and a few other properties populated. Then you want to retrieve those authors from the database to update those properties.

The WhereBulkContains method will filter entities to include those contained in the list.

var dictDeserializedCustomers = deserializedCustomers.ToDictionary(x => x.CustomerID);

using (var context = new EntityContext())
{
    var customers = context.Customers.WhereBulkContains(deserializedCustomers).ToList();

    customers.ForEach(x =>
    {
        var deserializedCustomer = dictDeserializedCustomers[x.CustomerID];

        x.Code = deserializedCustomer.Code;
        x.Email = deserializedCustomer.Email;
        x.FirstName = deserializedCustomer.FirstName;
        x.LastName = deserializedCustomer.LastName;
    });

    context.BulkSaveChanges();
}

Note